﻿/* 
 *  <copyright file="HealthCmp.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework.Graphics;
using SobrietyEngine.Components.Common;
using SobrietyEngine.Common;
using SobrietyEngine.Guids;
using Microsoft.Xna.Framework;
using SobrietyEngine.Actor;
using SobrietyEngine.Events;
using SobrietyEngine.Events.Actor;
using SobrietyEngine.Events.Component;

namespace SobrietyEngine.Components.Health
{
    public class HealthCmp : BaseComponent, SobrietyEngine.Components.IComponent
    {
        public float Health { get; set; }

        public HealthCmp()
            : base()
        {
            Health = 1.0f;
        }

        override public void Set(Parameters parms)
        {
            parms.GetValueAs<float>("Health", 1.0f);
        }

        public override Boolean InitComponent()
        {
            return base.InitComponent();
        }

        public void Damage(float amount, CGuid by)
        {
            Health -= amount;   
            Actor.EventRouter.RaiseEvent(this, new HealthChanged(Actor.Guid, amount * -1, Health, by));
        }

        public void Damage(float amount)
        {
            Health -= amount;
            Actor.EventRouter.RaiseEvent(this, new HealthChanged(Actor.Guid, amount * -1, Health));
        }

        public void Restore(float amount, CGuid by)
        {
            Health += amount;
            Actor.EventRouter.RaiseEvent(this, new HealthChanged(Actor.Guid, amount, Health, by));
        }

        public void Restore(float amount)
        {
            Health += amount;
            Actor.EventRouter.RaiseEvent(this, new HealthChanged(Actor.Guid, amount, Health));
        }

        new public void Update(GameTime elapsedTime)
        {
        }
    }
}
